package com.apex.aolonfitdemo.ui;

import android.content.Intent;
import android.os.Bundle;
import android.os.Looper;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.fastjson.JSONObject;
import com.apex.aolonfitdemo.R;
import com.apex.aolonfitdemo.databinding.ActivityCustomBinding;
import com.apex.aolonfitdemo.dialog.WaitingDialog;
import com.apex.ax_bluetooth.callback.WatchInfoCallback;
import com.apex.ax_bluetooth.core.EABleManager;
import com.apex.ax_bluetooth.enumeration.EABleConnectState;
import com.apex.ax_bluetooth.enumeration.QueryWatchInfoType;
import com.apex.ax_bluetooth.model.EABleWatchInfo;

public class CustomWatchFace extends AppCompatActivity {
    ActivityCustomBinding activityCustomBinding;
    EABleWatchInfo mEABleWatchInfo;
    WaitingDialog waitingDialog;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        activityCustomBinding = ActivityCustomBinding.inflate(getLayoutInflater());
        setContentView(activityCustomBinding.getRoot());
        activityCustomBinding.tool.setNavigationIcon(R.mipmap.exit_page);
        setSupportActionBar(activityCustomBinding.tool);
        getSupportActionBar().setTitle(null);
        activityCustomBinding.tool.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        activityCustomBinding.submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(CustomWatchFace.this, DiffColorTxtDialActivity.class);
                intent.putExtra("watchInfo", JSONObject.toJSONString(mEABleWatchInfo));
                startActivity(intent);
            }
        });
        activityCustomBinding.point.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(CustomWatchFace.this, PointDialActivity.class);
                intent.putExtra("watchInfo", JSONObject.toJSONString(mEABleWatchInfo));
                startActivity(intent);

            }
        });
        if (waitingDialog == null) {
            waitingDialog = new WaitingDialog(CustomWatchFace.this);
        }
        waitingDialog.show();
        EABleManager.getInstance().queryWatchInfo(QueryWatchInfoType.watch_info, new WatchInfoCallback() {
            @Override
            public void watchInfo(EABleWatchInfo eaBleWatchInfo) {
                if (eaBleWatchInfo != null) {
                    mEABleWatchInfo = eaBleWatchInfo;
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            if (waitingDialog != null) {
                                if (waitingDialog.isShowing()) {
                                    waitingDialog.dismiss();
                                }
                            }
                            activityCustomBinding.submit.setVisibility(View.VISIBLE);
                            activityCustomBinding.point.setVisibility(View.VISIBLE);
                        }
                    });

                }

            }

            @Override
            public void mutualFail(int i) {

            }
        });

    }
}
